<?php

namespace App\Http\Controllers\User;

use App\Http\Controllers\Controller;
use App\Service\UserService;
use function foo\func;
use Illuminate\Http\Request;
/**
 * @group 钱包
 *
 * APIs for managing users
 */
class WalletController extends Controller
{
    /**
     * Withdrawal  提现申请
     * @time:2020/2/19-10:24
     * @author:dongdong
     * @bodyParam money required 提现金额 Example: 100
     * @response {
     * "data": {
     * },
     * "status_code": 200,
     * "message" : "success"
     * }
     */
    public function withdrawal(Request $request)
    {
        $user = auth()->user();
        $max = $user->wallet;

        $data = $request->validate(
            [
                'money' => [
                    'integer',
                    'required',
                    'numeric',
                    'min:1',
                    "max:{$max}",
                    function ($attribute,$value, $fail) {

                    }
                ]
            ],
            [
                'integer' => '必须是整数',
                'numeric' => '必须是数字',
                'max' => '钱包金额不足余额:'.$user->wallet,
            ]
       );

       (new UserService() )->WithdrawalApply($user, $data['money']);
        return returnData();

    }

    /**
     * walletRecord 钱包全部记录
     * @time:2020/2/20-10:47
     *
     * @author:dongdong
     * @response {
     * "data": {
     * },
     * "status_code": 200,
     * "message" : "success"
     * }
     */
    public function walletRecord()
    {
        $user = auth()->user();
        $data = (new UserService())->walletRecord($user);
        return returnData($data);
    }

    /**
     * walletIncaseRecord   钱包收入记录
     * @time:2020/2/20-10:48
     *
     * @author:dongdong
     * @response {
     * "data": {
     * },
     * "status_code": 200,
     * "message" : "success"
     * }
     */
    public function walletIncaseRecord()
    {
        $user = auth()->user();
        $data = (new UserService())->walletIncreaseRecord($user);
        return returnData($data);

    }

    /**
     * walletDecaseRecorc 钱包减少记录
     * @time:2020/2/20-10:48
     *
     * @author:dongdong
     * @response {
     * "data": {
     * },
     * "status_code": 200,
     * "message" : "success"
     * }
     */
    public function walletDecaseRecorc()
    {
        $user = auth()->user();
        $data = (new UserService())->walletDecreaseRecord($user);
        return returnData($data);
    }

    /**
     * WithdrawalApply 提现单记录
     * @time:2020/2/20-10:59
     *
     * @author:dongdong
     * @response {
     * "data": {
     * },
     * "status_code": 200,
     * "message" : "success"
     * }
     */
    public function WithdrawalApply()
    {
        $user = auth()->user();
        $data = (new UserService())->WalletApplyRecord($user);
        return returnData($data);
    }
}
